package com.wh.dle;

import com.rabbitmq.client.Channel;
import com.wh.utils.ConnectionUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @Auther: HuiEr
 * @Date: 2020/3/12 12:58
 * @Description
 */
public class Handle {

    public static final String TTL_QUEUE_NAME="ttl_queue";
    public static final String TTL_EXCHANGE_NAME="ttl_exchange";
    public static final String DLE_QUEUE_NAME="dle_queue";
    public static final String DLE_EXCHANGE_NAME="dle_exchange";
    public static final String EXCHANGE_TYPE="fanout";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = ConnectionUtil.getConnection().createChannel();
        Map<String,Object> map=new HashMap<>();
        map.put("x-message-ttl",10000);
        map.put("x-dead-letter-exchange",DLE_EXCHANGE_NAME);
        channel.queueDelete(TTL_QUEUE_NAME);
        channel.queueDeclare(TTL_QUEUE_NAME,false,false,false,map);
        channel.exchangeDelete(TTL_EXCHANGE_NAME);
        channel.exchangeDeclare(TTL_EXCHANGE_NAME,EXCHANGE_TYPE);
        channel.queueBind(TTL_QUEUE_NAME,TTL_EXCHANGE_NAME,"",null);

        channel.queueDelete(DLE_QUEUE_NAME);
        channel.queueDeclare(DLE_QUEUE_NAME,false,false,false,null);
        channel.exchangeDelete(DLE_EXCHANGE_NAME);
        channel.exchangeDeclare(DLE_EXCHANGE_NAME,EXCHANGE_TYPE);
        channel.queueBind(DLE_QUEUE_NAME,DLE_EXCHANGE_NAME,"",null);
    }

}
